package com.liwq.base.threadlocal;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author : liwq
 * @version : 1.0
 * @date : 2022/7/20
 **/
public class ThreadLocalTest {

    private static ExecutorService service = Executors.newCachedThreadPool();

    public static void main(String[] args) {

        ThreadLocal<Boolean> threadLocal = ThreadLocal.withInitial(() -> {
            return false;
        });

        threadLocal.set(Boolean.TRUE);
        service.execute(() ->

        {
            threadLocal.set(Boolean.FALSE);
            System.out.println("子线程设置为：" + threadLocal.get());
        });
        System.out.println("主线程设置为：" + threadLocal.get());
        service.shutdown();
    }
}